<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>tabrenderer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_tabrenderer.js.html">tabrenderer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Default renderer for {@link goog.ui.Tab}s.  Based on the
<a name="line17"></a> * original {@code TabPane} code.
<a name="line18"></a> *
<a name="line19"></a> * @author attila@google.com (Attila Bodis)
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.ui.TabRenderer&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.a11y.aria.Role&#39;);
<a name="line25"></a>goog.require(&#39;goog.ui.Component.State&#39;);
<a name="line26"></a>goog.require(&#39;goog.ui.ControlRenderer&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * Default renderer for {@link goog.ui.Tab}s, based on the {@code TabPane} code.
<a name="line32"></a> * @constructor
<a name="line33"></a> * @extends {goog.ui.ControlRenderer}
<a name="line34"></a> */
<a name="line35"></a>goog.ui.TabRenderer = function() {
<a name="line36"></a>  goog.ui.ControlRenderer.call(this);
<a name="line37"></a>};
<a name="line38"></a>goog.inherits(goog.ui.TabRenderer, goog.ui.ControlRenderer);
<a name="line39"></a>goog.addSingletonGetter(goog.ui.TabRenderer);
<a name="line40"></a>
<a name="line41"></a>
<a name="line42"></a>/**
<a name="line43"></a> * Default CSS class to be applied to the root element of components rendered
<a name="line44"></a> * by this renderer.
<a name="line45"></a> * @type {string}
<a name="line46"></a> */
<a name="line47"></a>goog.ui.TabRenderer.CSS_CLASS = goog.getCssName(&#39;goog-tab&#39;);
<a name="line48"></a>
<a name="line49"></a>
<a name="line50"></a>/**
<a name="line51"></a> * Returns the CSS class name to be applied to the root element of all tabs
<a name="line52"></a> * rendered or decorated using this renderer.
<a name="line53"></a> * @return {string} Renderer-specific CSS class name.
<a name="line54"></a> * @override
<a name="line55"></a> */
<a name="line56"></a>goog.ui.TabRenderer.prototype.getCssClass = function() {
<a name="line57"></a>  return goog.ui.TabRenderer.CSS_CLASS;
<a name="line58"></a>};
<a name="line59"></a>
<a name="line60"></a>
<a name="line61"></a>/**
<a name="line62"></a> * Returns the ARIA role to be applied to the tab element.
<a name="line63"></a> * See http://wiki/Main/ARIA for more info.
<a name="line64"></a> * @return {goog.a11y.aria.Role} ARIA role.
<a name="line65"></a> * @override
<a name="line66"></a> */
<a name="line67"></a>goog.ui.TabRenderer.prototype.getAriaRole = function() {
<a name="line68"></a>  return goog.a11y.aria.Role.TAB;
<a name="line69"></a>};
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>/**
<a name="line73"></a> * Returns the tab&#39;s contents wrapped in a DIV, with the renderer&#39;s own CSS
<a name="line74"></a> * class and additional state-specific classes applied to it.  Creates the
<a name="line75"></a> * following DOM structure:
<a name="line76"></a> * &lt;pre&gt;
<a name="line77"></a> *   &lt;div class=&quot;goog-tab&quot; title=&quot;Title&quot;&gt;Content&lt;/div&gt;
<a name="line78"></a> * &lt;/pre&gt;
<a name="line79"></a> * @param {goog.ui.Control} tab Tab to render.
<a name="line80"></a> * @return {Element} Root element for the tab.
<a name="line81"></a> * @override
<a name="line82"></a> */
<a name="line83"></a>goog.ui.TabRenderer.prototype.createDom = function(tab) {
<a name="line84"></a>  var element = goog.ui.TabRenderer.superClass_.createDom.call(this, tab);
<a name="line85"></a>
<a name="line86"></a>  var tooltip = tab.getTooltip();
<a name="line87"></a>  if (tooltip) {
<a name="line88"></a>    // Only update the element if the tab has a tooltip.
<a name="line89"></a>    this.setTooltip(element, tooltip);
<a name="line90"></a>  }
<a name="line91"></a>
<a name="line92"></a>  return element;
<a name="line93"></a>};
<a name="line94"></a>
<a name="line95"></a>
<a name="line96"></a>/**
<a name="line97"></a> * Decorates the element with the tab.  Initializes the tab&#39;s ID, content,
<a name="line98"></a> * tooltip, and state based on the ID of the element, its title, child nodes,
<a name="line99"></a> * and CSS classes, respectively.  Returns the element.
<a name="line100"></a> * @param {goog.ui.Control} tab Tab to decorate the element.
<a name="line101"></a> * @param {Element} element Element to decorate.
<a name="line102"></a> * @return {Element} Decorated element.
<a name="line103"></a> * @override
<a name="line104"></a> */
<a name="line105"></a>goog.ui.TabRenderer.prototype.decorate = function(tab, element) {
<a name="line106"></a>  element = goog.ui.TabRenderer.superClass_.decorate.call(this, tab, element);
<a name="line107"></a>
<a name="line108"></a>  var tooltip = this.getTooltip(element);
<a name="line109"></a>  if (tooltip) {
<a name="line110"></a>    // Only update the tab if the element has a tooltip.
<a name="line111"></a>    tab.setTooltipInternal(tooltip);
<a name="line112"></a>  }
<a name="line113"></a>
<a name="line114"></a>  // If the tab is selected and hosted in a tab bar, update the tab bar&#39;s
<a name="line115"></a>  // selection model.
<a name="line116"></a>  if (tab.isSelected()) {
<a name="line117"></a>    var tabBar = tab.getParent();
<a name="line118"></a>    if (tabBar &amp;&amp; goog.isFunction(tabBar.setSelectedTab)) {
<a name="line119"></a>      // We need to temporarily deselect the tab, so the tab bar can re-select
<a name="line120"></a>      // it and thereby correctly initialize its state.  We use the protected
<a name="line121"></a>      // setState() method to avoid dispatching useless events.
<a name="line122"></a>      tab.setState(goog.ui.Component.State.SELECTED, false);
<a name="line123"></a>      tabBar.setSelectedTab(tab);
<a name="line124"></a>    }
<a name="line125"></a>  }
<a name="line126"></a>
<a name="line127"></a>  return element;
<a name="line128"></a>};
<a name="line129"></a>
<a name="line130"></a>
<a name="line131"></a>/**
<a name="line132"></a> * Takes a tab&#39;s root element, and returns its tooltip text, or the empty
<a name="line133"></a> * string if the element has no tooltip.
<a name="line134"></a> * @param {Element} element The tab&#39;s root element.
<a name="line135"></a> * @return {string} The tooltip text (empty string if none).
<a name="line136"></a> */
<a name="line137"></a>goog.ui.TabRenderer.prototype.getTooltip = function(element) {
<a name="line138"></a>  return element.title || &#39;&#39;;
<a name="line139"></a>};
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * Takes a tab&#39;s root element and a tooltip string, and updates the element
<a name="line144"></a> * with the new tooltip.  If the new tooltip is null or undefined, sets the
<a name="line145"></a> * element&#39;s title to the empty string.
<a name="line146"></a> * @param {Element} element The tab&#39;s root element.
<a name="line147"></a> * @param {string|null|undefined} tooltip New tooltip text (if any).
<a name="line148"></a> */
<a name="line149"></a>goog.ui.TabRenderer.prototype.setTooltip = function(element, tooltip) {
<a name="line150"></a>  if (element) {
<a name="line151"></a>    element.title = tooltip || &#39;&#39;;
<a name="line152"></a>  }
<a name="line153"></a>};
</pre>


</body>
</html>
